home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / RCShaders / RCSDixon.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.0 KB  |  37 lines

  1. /* Listing 16.37  Pencil-labeling surface shader*/
  2. /*
  3.  * sdixon(): Paint the body of a pencil.
  4.  */
  5. surface
  6. RCSDixon(
  7.     float    Ka        = 1.0, 
  8.         Kd        = 1.0, 
  9.         Ks        = 1.0,
  10.          roughness     = .25;
  11.     color    green         = color(0, .2, 0), 
  12.         yellow         = color(.56, .23, 0);
  13.     string    texturename    = "")
  14. {
  15.     point Nf = faceforward(normalize(N),I);
  16.     point V = normalize(-I);
  17.     float ink;
  18.     color cout;
  19.  
  20.     /* This shader uses a single-channel texture map to apply a 
  21.      *   metallic-green ink to a matte-yellow background. */
  22.  
  23.     /* Get the amount of ink from texture file. */
  24.     ink = texture(texturename, s, t);
  25.  
  26.      /* Use ink to mix yellow and green */
  27.     cout = mix(yellow, green, ink);                      
  28.  
  29.     /* Compute the output color. Notice that as ink goes from zero to
  30.        one, the diffuse component goes to zero and the specular 
  31.        component is increased. This has the effect of transitioning
  32.        from a matte surface to a metallic one as ink is added. */
  33.     Oi = Os;
  34.     Ci = Os * cout * ( Ka*ambient() + (1-ink)*Kd*diffuse(Nf) +
  35.                     ink*Ks*specular(Nf,V,roughness) ) ;
  36. }
  37.